import celery


def patch_celery_console(celery_instance: celery.Celery):
    import logging
    from nb_log.handlers import ColorHandler
    logging.StreamHandler = ColorHandler  # 解决celery的颜色不好看的问题

    # 设置celery的conf配置项，解决日志可点击跳转问题。
    # print(celery_app.conf)
    celery_instance.conf.worker_task_log_format = '%(asctime)s - %(name)s - "%(pathname)s:%(lineno)d" - %(funcName)s - %(levelname)s - %(message)s'
    celery_instance.conf.worker_log_format = '%(asctime)s - %(name)s - "%(pathname)s:%(lineno)d" - %(funcName)s - %(levelname)s - %(message)s'

    # 禁止print重定向，不希望print被转化成celery日志。配置这个。
    celery_instance.conf.worker_redirect_stdouts = False
